<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/pages/common/header.jsp" %>
<title>版本编辑</title>
<script type="text/javascript">
	var version_id="${param.version_id}";
	$(function() {
		if(version_id){
			$.ajax({
				type: "post",
				url: "${baseURL}/versioninfo/detail.action",
						data : "version_Id=" + version_id,
						dataType : "json",
						success : function(result) {
							$("#versionId").val(result.versionId);
							$("#versionNumber").val(result.versionNumber);
							$("#publisher").val(result.publisher);
							$("#publishTime").val(result.publishTime_str);
							var s1="";
							var s2="";
							if(result.versionDetailInfoVOs.length>0){
								s1="<tr height='30'><td>&nbsp;</td><td><input type='text' name='seq_Num' size='5' value='"+result.versionDetailInfoVOs[0].seq_Num+"' class='liger-textbox' maxlength='3'/></td><td><input type='text' name='content' size='110' value='"+result.versionDetailInfoVOs[0].content+"' class='content'/></td></tr>";
								for ( var i = 1; i < result.versionDetailInfoVOs.length; i++) {
									s2 += "<tr height='30'><td><button class='del'>删除</button></td><td><input type='text' name='seq_Num' size='5' value='"+result.versionDetailInfoVOs[i].seq_Num+"' maxlength='3'/></td><td><input type='text' name='content' size='110' value='"+result.versionDetailInfoVOs[i].content+"'/></td></tr>";
								}
							}
							$("#versionDetail").append(s1+s2);
						}
					});
			}else{
				$("#versionDetail").append("<tr height='30'><td>&nbsp;</td><td><input type='text' name='seq_Num' size='5'  value='1' maxlength='3'/></td><td><input type='text' name='content' size='110' value='' class='content'/></td></tr>");
			}
		
		//初始换日期选择框
		$("#publishTime").ligerDateEditor({
			showTime : false,
			labelWidth : 100,
			labelAlign : 'left'
		});
		//删除行事件
		$(".del").live("click", function() {
			$(this).parent().parent().remove();
		});
		//新增空行事件
		$("#btnNewRow").click(function(){
			var value=$("input[name='seq_Num']:last").val();
			if(typeof(value)=="undefined"){
				value=0;
			}
			var nextvalue=parseInt(value)+1;
			$("#versionDetail")
					.append(
							"<tr height='30'><td><button class='del'>删除</button></td><td><input type='text' name='seq_Num' size='5' value='"+
							nextvalue+"'/></td><td><input type='text' name='content' size='110'/></td></tr>");
		});
	});

	
	function editversionInfo(isNew){
		var falg = true;
		$("input[name='content']").each(function(){
			if($(this).val().trim() == ''){
				falg = false;
				alert('内容不可为空');
				return false;
			}
		});
		$("input[name='seq_Num']").each(function(){
			if($(this).val().trim() == '' && isNaN($(this).val())){
				falg = false;
				alert('序号不可空且为数字!');
				return false;
			}
		});
		if(!falg) {
			return false;
		}
		
		$.ajax({
			async : false,
			cache : false,
			type : "post",
			data: $("#form1").serialize(), 
			dataType:'json',
			url : "${baseURL}/versioninfo/save.action",
			success : function(data) {
				if(data && data.hasOk){
					alert("操作成功!");	
					falg = true;
				}
			},
			error : function() {
				$.ligerDialog.error('服务器出错，操作失败，请重试!');
			}
		});
		return falg;
	}
</script>
</head>
<body>
<form id="form1" >
<input type="hidden" id="versionId" name="versionInfoVO.versionId" value=""/>
	  	<table class="form4column">
	  		<tr>
	  			<td class="label"><span style="color:red">*</span>版本号:</td>
	  			<td class="content"><input type="text" id="versionNumber" name="versionInfoVO.versionNumber" class="input-common" dataType="Require"  /></td>
	  			<td class="label"><span style="color:red">*</span>发布人:</td>
	  			<td class="content"><input type="text" id="publisher" name="versionInfoVO.publisher" class="input-common" dataType="Require"  /></td>
	  		</tr>
	  		<tr>
	  			<td class="label"><span style="color:red">*</span>版本日期:</td>
	  			<td class="content" colspan="3">
	  			<input type="text" id="publishTime" class="input-common" name="versionInfoVO.publishTime" readonly="true"/></td>
	  		</tr>
           <tr>
           		<td align="center" colspan="4">
				<table id="versionDetail" class="form_list">
					<tr class="title"><td width="10%"><input type="button" value="增行" id="btnNewRow"/></td><td width="10%">序号</td><td width="80%">内容</td></tr>
				</table>           
				</td>
           </tr> 
	  	</table>
	  </form>
<br/><br/><br/>
</body>
</html>
